<?php

// 4/10/2010: immanuel192 write this action

if (!defined('EXPONENT')) exit('');

$song_id = -1; 
global $db;

// test song id
if (isset($_GET['id']))
{
	$_GET['id']=intval($_GET['id']);
	$song_id=$_GET['id'];
	$object = $db->selectObject('present_songs','id='.intval($_GET['id']));
	if (!$object) die("ERROR");
	// 
	$playlist=exponent_sessions_getTicketString();
	$pl=$db->selectObject('present_playlist','session = "' . $playlist .'"');
	if ($pl==null)
		{
			$pl=null; $pl->session=$playlist; $pl->create_time=$time;
			$pl->id=$db->insertObject($pl,"present_playlist");
		}
	$pl_song=$db->selectObject("present_playlist_songs","playlist_id = " . $pl->id . " AND song_id = " . $song_id);
	if (!$pl_song)
	{
		$pl_song=null;
		$pl_song->playlist_id=$pl->id; $pl_song->song_id=$song_id;
		$pl_song->rank = $db->max('present_playlist_songs', 'rank', 'playlist_id', "playlist_id  = ".$pl->id);
		if ($pl_song->rank == null) {
			$pl_song->rank = 0;
		} else {
			$pl_song->rank += 1;
		}
		$db->insertObject($pl_song,"present_playlist_songs");
	}
	die($song_id."OK");
}
else
 die("ERROR");


?>
